package com.zzw.bridge.security.utils;

import cn.hutool.core.lang.UUID;
import com.alibaba.fastjson2.util.UUIDUtils;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * token工具类
 *
 * @author Xiaojie
 * @date 2025/05/20 05:20
 */
public class TokenUtils {

	/**
	 * 生成 AccessToken
	 */
	public static String generator () {
		return UUID.fastUUID().toString(true);
	}

	/**
	 * 获取 AccessToken
	 */
	public static String getAccessToken (HttpServletRequest request) {
		//从请求头中获取token
		String accessToken = request.getHeader("Authorization");
		if (StringUtils.isBlank(accessToken)) {
			//从请求路径？后获取token（使用去get/表单请求）
			accessToken = request.getParameter("Authorization");
		}

		return accessToken;
	}
}
